/****************************************************************
 *Author:       zxx
 *UnityVersion：2019.4.1f1
 *Date:         2020/07/30 16:40:53
 *Description:    
*****************************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GamePanel : MonoBehaviour {


    private Text diamontCount,gameOverTimer;

    private Button btnJump;


    // private ButtonExtension btnLeft,btnRight;
    private Button btnLeft;
    private Button btnRight;

    private Toggle invincible;

    // Use this for initialization
    void Start () {
        diamontCount = transform.Find("Diamond/Count").GetComponent<Text>();

        gameOverTimer = transform.Find("GameOverTimer/Count").GetComponent<Text>();

        btnJump = transform.Find("BtnJump").GetComponent<Button>();
        btnJump.onClick.AddListener(BtnJumpOnClick);


        //btnLeft = transform.Find("BtnLeft").GetComponent<ButtonExtension>();
        //btnLeft.onPress.AddListener(BtnLeftOnPress);
        btnLeft = transform.Find("BtnLeft").GetComponent<Button>();
        

        btnRight = transform.Find("BtnRight").GetComponent<Button>();


        invincible = transform.Find("Invincible").GetComponent<Toggle>();
        invincible.onValueChanged.AddListener(Invincible);
    }
    

    private void BtnJumpOnClick()
    {

        EventCenter.Broadcast(EventDefine.PlayerJump);
        EventCenter.Broadcast(EventDefine.ReocketSpawn);


    }

    private void Invincible(bool value)
    {
        GameMananger.Instance.invincible = value;
    }

    public void BtnRightOnPress()
    {
        EventCenter.Broadcast(EventDefine.PlayerRightDown);
        EventCenter.Broadcast(EventDefine.ReocketSpawn);

    }
    public void BtnRightUp()
    {
        EventCenter.Broadcast(EventDefine.PlayerRightUp);
    }


    public void BtnLeftOnPress()
    {
        Debug.Log("按下");
        EventCenter.Broadcast(EventDefine.PlayerLeftDown);
        EventCenter.Broadcast(EventDefine.ReocketSpawn);

    }
    public void BtnLeftUp()
    {
        Debug.Log("抬起");
        EventCenter.Broadcast(EventDefine.PlayerLeftUp);

    }



    private void Update()
    {
        diamontCount.text ="X"+ GameMananger.Instance.diamontCount.ToString();
        gameOverTimer.text = (int)GameMananger.Instance.gameOverTimer +"s";
    }
}

